from db import Session
from db.bidding import ShopMeituanInfo


def getmtIdByShopAccount(account):
    """
    通过shopId获取id
    :param shopId:
    :return:
    """
    session = Session()
    try:
        account = session.query(ShopMeituanInfo.id).filter(ShopMeituanInfo.account == account).scalar()
        if account:
            return account
        else:
            return -1
    except:
        session.rollback()
        return -1
    finally:
        session.close()
def getAllMtShop():
    """获取所有的美团店铺"""
    session = Session()
    try:
        shopInfo = session.query(ShopMeituanInfo.mtName, ShopMeituanInfo.cookies).filter(ShopMeituanInfo.deleted == 0).all()
        if shopInfo:
            return shopInfo
        else:
            return 0
    except:
        session.rollback()
        return 0
    finally:
        session.close()

def getIpFromShopMeituanInfo(account, shopType):
    """
    获取当前店铺的ip
    :param account:
    :param shopType:
    :return:
    """
    session = Session()
    try:
        ip = session.query(ShopMeituanInfo.ip).filter(ShopMeituanInfo.account == account).scalar()
        session.close()
        if ip:
            return ip
        else:
            return None
    except:
        session.close()
        return -1
